package cn.wjh.business.service.impl;

import cn.wjh.business.asyncTask.BusinessAsyncFactory;
import cn.wjh.business.domain.Language;
import cn.wjh.business.mapper.LanguageMapper;
import cn.wjh.business.service.ILanguageService;
import cn.wjh.business.service.ITranslateService;
import cn.wjh.common.utils.DateUtils;
import cn.wjh.common.utils.SecurityUtils;
import cn.wjh.framework.manager.AsyncManager;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 翻译语种Service业务层处理
 *
 * @author jiraWu
 * @date 2023-11-30
 */
@Service
public class LanguageServiceImpl extends ServiceImpl<LanguageMapper, Language> implements ILanguageService {
    @Resource
    private LanguageMapper languageMapper;

    @Resource
    private ITranslateService translateService;

    /**
     * 查询翻译语种
     *
     * @param languageId 翻译语种主键
     * @return 翻译语种
     */
    @Override
    public Language selectLanguageByLanguageId(Long languageId) {
        return languageMapper.selectLanguageByLanguageId(languageId);
    }

    /**
     * 查询翻译语种列表
     *
     * @param language 翻译语种
     * @return 翻译语种
     */
    @Override
    public List<Language> selectLanguageList(Language language) {
        return languageMapper.selectLanguageList(language);
    }

    /**
     * 新增翻译语种
     *
     * @param language 翻译语种
     * @return 结果
     */
    @Override
    public int insertLanguage(Language language) {
        language.setCreateTime(DateUtils.getNowDate());
        language.setCreateBy(SecurityUtils.getUsername());
        //        if (rows > 0) {
//            /*异步添加一下这个语言的所有词条*/
//            AsyncManager.me().execute(BusinessAsyncFactory.saveLanguageAfter(language, SecurityUtils.getUsername(), SecurityUtils.getUserId()));
//        }
        return languageMapper.insertLanguage(language);
    }

    /**
     * 修改翻译语种
     *
     * @param language 翻译语种
     * @return 结果
     */
    @Override
    public int updateLanguage(Language language) {
        language.setUpdateTime(DateUtils.getNowDate());
        return languageMapper.updateLanguage(language);
    }

    /**
     * 批量删除翻译语种
     *
     * @param languageIds 需要删除的翻译语种主键
     * @return 结果
     */
    @Override
    public int deleteLanguageByLanguageIds(List<Long> languageIds) {
        return languageMapper.deleteBatchIds(languageIds);
    }

    /**
     * 删除翻译语种信息
     *
     * @param languageId 翻译语种主键
     * @return 结果
     */
    @Override
    public int deleteLanguageByLanguageId(Long languageId) {
        return languageMapper.deleteLanguageByLanguageId(languageId);
    }

    /**
     * 获取全部语言
     */
    @Override
    public List<Language> selectList() {
        return this.list();
    }
}
